package cn.kk.Blog.dao.impl;
/*
 *@author KK on 2022.12.01 21:10
 */

import cn.kk.Blog.core.utils.DBUtils;
import cn.kk.Blog.dao.ISystemUserDao;
import cn.kk.Blog.entity.TSystemUser;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class SystemUserDaoImpl implements ISystemUserDao {
    private QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
    @Override
    public Integer insert(TSystemUser tSystemUser) throws Exception {
        String sql = "INSERT INTO t_system_user VALUES(DEFAULT,?,?,?,?,?,?,DEFAULT)";
        return qr.update(sql,tSystemUser.getUsername(),tSystemUser.getPassword(),tSystemUser.getSex(),tSystemUser.getEmail(),new Date(),tSystemUser.getBirthday());
    }

    @Override
    public TSystemUser selectById(Integer id) throws Exception {
        return null;
    }

    @Override
    public Integer updateById(TSystemUser tSystemUser) throws Exception {
        return null;
    }

    @Override
    public Integer deleteById(Integer id) throws Exception {
        return null;
    }

    @Override
    public List<TSystemUser> selectList() throws Exception {
        String sql = "select * from t_system_user where status = 0";
        return qr.query(sql, new BeanListHandler<TSystemUser>(TSystemUser.class));
    }

    @Override
    public Integer batchRemove(List<Integer> ids) throws Exception {
        return null;
    }

    @Override
    public TSystemUser getUserByName(String username) throws SQLException {
        String sql = "select * from t_system_user where username = ? ";
        return qr.query(sql,new BeanHandler<TSystemUser>(TSystemUser.class),username);
    }

    @Override
    public TSystemUser selectByName(String name) throws Exception {
        return null;
    }
}
